package com.zktr.utils;

import java.sql.*;

public class BaseDAO {
	private static final String DRIVER="com.mysql.jdbc.Driver";
	private static final String URL="jdbc:mysql://localhost:3306/jdproject";
	private static final String USERNAME="root";
	private static final String PASSWORD="";
	
	/**
     *
     *释放对象占用的数据库联接资源
	 * @param con
	 * @param st
	 * @param rt
	 */
	public static void closeAll(Connection con,Statement st,ResultSet rt) {
		try {
			if(rt!=null){
				rt.close();
				rt=null;
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		try {
			if(st!=null){
				st.close();
				st=null;
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		try {
			if(con!=null){
				con.close();
				con=null;
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
	}

	/**
	 * 创建连接对象
	 * @return
	 */
	public  static Connection getConnections() {
		try {
			Class.forName(DRIVER);
			return DriverManager.getConnection(URL,USERNAME,PASSWORD);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}
	
}
